/**
 *计算日历的某一天 距离现在的天树
*/
let time = new Date()
let day_now  = Number(time.getDate());
let month_now = Number(time.getMonth())+1;//返回的是0-11
let year_now = Number(time.getFullYear());
let week_now = time.getDay();
switch (week_now) {
  case 1:
    week_now = '星期一'
    break;
  case 2 :
    week_now = '星期二'
    break
  case 3 :
    week_now = '星期三'
    break
  case 4 :
    week_now = '星期四'
    break
  case 5 :
    week_now = '星期五'
    break
  case 6 :
    week_now = '星期六'
    break
  case 0 :
    week_now = '星期日'
    break
  default:
    break;
}

function calcDayNum (year,month,day) {
  let year_gap = Math.abs(Number(year) - year_now);
  let totolDay_now = year_now % 4 == 0? 366: 355;
  let totolDay_aim = year_now % 4 == 0? 366: 355;
  //年相差天数
  let min = year_now > year? year:year_now;
  let count = 0;
  for(let i = min; i < year_gap+min-1; i++) {
    if(i % 4 == 0) {
      count += 366;
    }else{
      count += 365;
    }
  }
  //计算月份差距
  let count_now = 0,count_aim = 0;
  let day_tow = 0;
    //判断2月份的天使
    if(year % 4 == 0) {
      day_tow = 29;
    }else{
      day_tow = 28;
    }
  for(let i = 1; i < month; i++) {
    if(i <= 7 && i % 2 == 0 && i != 2) {
      count_aim += 30      
    }else if(i <= 7 && i % 2 == 1) {
      count_aim += 31
    }else if(i == 2) {
      count_aim += day_tow;
    }else if(i >= 8 && i % 2 == 0) {
      count_aim += 31;
    }else if(i >= 8 && i % 2 == 1) {
      count_aim += 30;
    }
  }
  //向下天数
  count_aim = count_aim + day;
  // console.log(count_aim)
  // console.log(count_aim)
  let day_tow_now = 0;
    //判断2月份的天使
    if(year_now % 4 == 0) {
      day_tow_now = 29;
    }else{
      day_tow_now = 28;
    }
  for(let i = 1; i < month_now; i++) {
    if(i <= 7 && i % 2 == 0 && i != 2) {
      count_now += 30      
    }else if(i <= 7 && i % 2 == 1) {
      count_now += 31
    }else if(i == 2) {
      count_now += day_tow;
    }else if(i >= 8 && i % 2 == 0) {
      count_now += 31;
    }else if(i >= 8 && i % 2 == 1) {
      count_now += 30;
    }
  }
  count_now = count_now  + day_now;
  // console.log(count_now)
  //相差总天数
  let dayAll = 0;
  if(year_gap == 0) {
    dayAll = count_aim - count_now
  }else if(year >= year_now){
    dayAll = totolDay_now - count_now + count_aim + count - 1
  }else if(year < year_now){
    dayAll = -(count_now + totolDay_aim - count_aim)+1
  }
  return dayAll;
}

//通过传入年月，判断这个月的天数；
function caclDayofMonth(year,month){
  month = month+1;
  year_type = 0;
  if(year % 4 == 0) {
    year_type = 0;  //闰年
  }else{
    year_type =1; //平年
  }
  let day_tow = 0;
    //判断2月份的天使
    if(year % 4 == 0) {
      day_tow = 29;
    }else{
      day_tow = 28;
    }
  let monthDay = 0;
  for(let i = 1; i < month; i++) {
    if(i <= 7 && i % 2 == 0 && i != 2) {
      monthDay = 30      
    }else if(i <= 7 && i % 2 == 1) {
      monthDay = 31
    }else if(i == 2) {
      monthDay = day_tow;
    }else if(i >= 8 && i % 2 == 0) {
      monthDay = 31;
    }else if(i >= 8 && i % 2 == 1) {
      monthDay = 30;
    }
  }
  return monthDay;
}
